package com.athena.crm.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.athena.crm.domain.bo.CrmClueTransferCustomerBo;
import com.athena.crm.domain.bo.CrmCustomerToHighSeasBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.athena.common.annotation.RepeatSubmit;
import com.athena.common.annotation.Log;
import com.athena.common.core.controller.BaseController;
import com.athena.common.core.domain.PageQuery;
import com.athena.common.core.domain.R;
import com.athena.common.core.validate.AddGroup;
import com.athena.common.core.validate.EditGroup;
import com.athena.common.core.validate.QueryGroup;
import com.athena.common.enums.BusinessType;
import com.athena.common.utils.poi.ExcelUtil;
import com.athena.crm.domain.vo.CrmCustomerHighSeasVo;
import com.athena.crm.domain.bo.CrmCustomerHighSeasBo;
import com.athena.crm.service.ICrmCustomerHighSeasService;
import com.athena.common.core.page.TableDataInfo;

/**
 * CRM客户公海
 *
 * @author ruoyi
 * @date 2023-09-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/crm/customerHighSeas")
public class CrmCustomerHighSeasController extends BaseController {

    private final ICrmCustomerHighSeasService iCrmCustomerHighSeasService;

    /**
     * 查询CRM客户公海列表
     */
    @SaCheckPermission("crm:customerHighSeas:list")
    @GetMapping("/list")
    public TableDataInfo<CrmCustomerHighSeasVo> list(CrmCustomerHighSeasBo bo, PageQuery pageQuery) {
        return iCrmCustomerHighSeasService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出CRM客户公海列表
     */
    @SaCheckPermission("crm:customerHighSeas:export")
    @Log(title = "CRM客户公海", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CrmCustomerHighSeasBo bo, HttpServletResponse response) {
        List<CrmCustomerHighSeasVo> list = iCrmCustomerHighSeasService.queryList(bo);
        ExcelUtil.exportExcel(list, "CRM客户公海", CrmCustomerHighSeasVo.class, response);
    }

    /**
     * 获取CRM客户公海详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("crm:customerHighSeas:query")
    @GetMapping("/{id}")
    public R<CrmCustomerHighSeasVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iCrmCustomerHighSeasService.queryById(id));
    }

    /**
     * 新增CRM客户公海
     */
    @SaCheckPermission("crm:customerHighSeas:add")
    @Log(title = "CRM客户公海", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CrmCustomerHighSeasBo bo) {
        return toAjax(iCrmCustomerHighSeasService.insertByBo(bo));
    }

    /**
     * 修改CRM客户公海
     */
    @SaCheckPermission("crm:customerHighSeas:edit")
    @Log(title = "CRM客户公海", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CrmCustomerHighSeasBo bo) {
        return toAjax(iCrmCustomerHighSeasService.updateByBo(bo));
    }

    /**
     * 删除CRM客户公海
     *
     * @param ids 主键串
     */
    @SaCheckPermission("crm:customerHighSeas:remove")
    @Log(title = "CRM客户公海", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iCrmCustomerHighSeasService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 客户转客户公海
     */
    @SaCheckPermission("crm:customerHighSeas:add")
    @Log(title = "客户转客户公海", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/transferCustomerToCustomerHighSeas")
    public R<Void> transferCustomerToCustomerHighSeas(@Validated(AddGroup.class) @RequestBody CrmCustomerToHighSeasBo bbo) {
        return toAjax(iCrmCustomerHighSeasService.customerToCustomerHighSeas(bbo));
    }

    /**
     * 客户公海转客户
     */
    @SaCheckPermission("crm:customerHighSeas:add")
    @Log(title = "客户公海转客户", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/transferCustomerHighSeasToCustomer")
    public R<Void> transferCustomerHighSeasToCustomer(@Validated(AddGroup.class) @RequestBody CrmCustomerToHighSeasBo bbo) {
        return toAjax(iCrmCustomerHighSeasService.customerSeasToCustomerHigh(bbo));
    }
}
